package edu.napier.soc.xfdm.model;

public class ConstraintException extends Exception {

	private final Constraint c;
	private final int row;

	public ConstraintException(Constraint c, int row) {
		super(getString(c, row));
		this.c = c;
		this.row = row;
	}

	private static String getString(Constraint c, int row) {
		if (row == 0) {
			return String.format("Error: Constraint %1$s failed %2$s " +
					"constraint check on attempted entity update", c.getName(),
					c.getConstraintType());
		} else {
			return String.format("Error: Constraint %1$s failed %2$s " +
					"constraint check on row %3$s", c.getName(),
					c.getConstraintType(), row);
		}
	}

	public Constraint getConstraint() {
		return c;
	}

	public int getRow() {
		return row;
	}
}
